'the easy function to write and read regedit just calling win32 api from one function.
'Declare this functions first from Win32API

Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.

Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.

Global Const HKEY_CLASSES_ROOT = &H80000000
Global Const HKEY_CURRENT_USER = &H80000001
Global Const HKEY_LOCAL_MACHINE = &H80000002
Global Const HKEY_USERS = &H80000003
Public RegTxt as string


Public Sub RegCtrl(hKey As Long, hSubKey As String, Rwrite As Boolean, value As String, dtype As Long, val1 As String)
Dim hnd, rnd As Long
hnd = RegCreateKey(hKey, hSubKey, rnd)
hnd = RegOpenKeyEx(hKey, hSubKey, 0, KEY_ALL_ACCESS, rnd)
If Rwrite = True Then
hnd = RegSetValueEx(rnd, value, 0, dtype, ByVal (val1), Len(val1))
Else
hnd = RegQueryValueEx(rnd, value, 0, dtype, ByVal (RegTxt), Len(RegTxt))
End If
hnd = RegCloseKey(hKey)
End Sub
